const express=require('express');
const mysql=require('mysql');
//const common=require('../../libs/common.js');
const urlobj=require('url');
const multer=require('multer');
//const multerObj=multer({dest:'../../www/upload'});
const pathLib=require('path');
const fs=require('fs');
//链接数据库
var db=mysql.createPool({
    host:'localhost',
    user:'root',
    password:'',
    database:'leasedb'
});
module.exports = function() {
	var router = express.Router();
	
	//查询用户信息
  router.post('/userinfoSelf', function(req, res) {
    db.query("SELECT * FROM `userinfo` WHERE userId="+ +req.body.userId+"",function(err,data){
      if(err)
      {
        res.send('{"status":"400"}').end();
      }
      else
      {
        if(data.length==0){
        	res.send('{"status":"300"}').end();
        }
        else{
        	res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
        }
      }
    });
  });
  
//修改用户信息
router.post('/userinfoUpdate', function(req, res) {
    db.query("UPDATE userinfo SET Nickname='"+req.body.Nickname +"',userImg='"+req.body.userImg+"',userPwd='"+req.body.userPwd+"',PayPwd='"+req.body.PayPwd+"',userAddr='"+req.body.userAddr+"',userEmail='"+req.body.userEmail+"' WHERE userId="+req.body.userId+"",function (err,data) {
                        if(err)
                        {
                           res.send('{"status":"400"}').end();
                        }else
                        {
                           res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
                        }
                    });
});
	
	return router;
}